package com.yaolaizaixian.merchant.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yaolaizaixian.merchant.R;
import com.yaolaizaixian.merchant.bean.Discount;
import com.yaolaizaixian.merchant.order.QueryResultActivity;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.List;

/**
 * Created by ylzx on 2017/2/27.
 */
public class DiscountBestAdapter extends RecyclerView.Adapter<DiscountBestAdapter.ViewHolder> {


    public List<Discount> datas;
    private QueryResultActivity mcontext;
    private OnItemClickListener mOnItemClickListener;
    private QueryResultActivity queryResultActivity;

    public DiscountBestAdapter(QueryResultActivity context, List<Discount> datas) {

        this.datas = datas;
        this.mcontext = context;
        queryResultActivity = (QueryResultActivity) context;
    }


    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {

        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_youhui, viewGroup, false);

        return new ViewHolder(view);
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {


    }

    //获取数据的数量
    @Override
    public int getItemCount() {

        if (null!=datas&&datas.size()>0)
        {
            return datas.size();
        }
        else
        {
            return 0;
        }
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_yuanhui_image;
        ImageView iv_use;
        ImageView iv_mengceng;
        TextView tv_youhui_name;
        TextView tv_youhui_time;
        AutoLinearLayout ll_use;
        Button bt_use;
        Button bt_unuse;

        public ViewHolder(View view) {
            super(view);

            iv_yuanhui_image= (ImageView) view.findViewById(R.id.iv_yuanhui_image);
            iv_use= (ImageView) view.findViewById(R.id.iv_use);
            iv_mengceng= (ImageView) view.findViewById(R.id.iv_mengceng);
            ll_use=(AutoLinearLayout) view.findViewById(R.id.ll_use);
            bt_use= (Button) view.findViewById(R.id.bt_use);
            bt_unuse=(Button) view.findViewById(R.id.bt_unuse);
            tv_youhui_name= (TextView) view.findViewById(R.id.tv_youhui_name);
            tv_youhui_time= (TextView) view.findViewById(R.id.tv_youhui_time);

        }
    }

    public interface OnItemClickListener {
        void onClick(int position);

        void onLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {

        this.mOnItemClickListener = onItemClickListener;
    }


}
